<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ include file="/taglibs.jsp"%>
<html>
<head>
<title>IT管理后台</title>
<link rel="stylesheet" type="text/css" href="/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="/js/themes/icon.css">
<script type="text/javascript" src="/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/js/easyui_validatebox.js"></script>
<script type="text/javascript" src="/js/locale/easyui-lang-zh_CN.js"></script>
<script src="/js/print.js" type="text/javascript"></script>
<style type="text/css">
table.ttb{border-left:solid 1px #99bbe8;border-top: solid 1px #99bbe8;}
table.ttb td{word-break: break-all; word-wrap:break-word;vertical-align: top; padding-left:8px; border-right: solid 1px #99bbe8;border-bottom: solid 1px #99bbe8; line-height: 24px; font-size: 12px;}
.bg001{font-weight: bold; color: #333; background-color: #edf4fc}
</style>
	<script>
	    var tag = null;
		$(function(){
			$('#tab').datagrid({
				title:'角色维护',
				iconCls:'icon-save',
				nowrap: false,
				singleSelect:true,
				striped: true,
				pageSize:20,
				pageList:[2,10,20,30,40,50,300],
				url:'/itmanager/yh/jswhjson',
				remoteSort: false,
				idField:'id',
				columns:[
					[
						{field:'mc',title:'角色名称',width:250,editor:{type:'validatebox',options:{required:true}}},
						{field:'sfyx',title:'是否有效',width:200,editor:{type:'combobox',options:{required:true,valueField:'dm',textField:'mc',data:[{dm:'0',mc:'否'},{dm:'1',mc:'是'}]}},formatter:function(value,rowData,rowIndex){
							if(value == '0'){
								return '<font color="red">否</font>';
							}
							if(value == '1'){
								return '是';
							}
						}}
					]
				],
				fit:true,
				border:false,
				pagination:true,
				rownumbers:true,
				toolbar:[{
					id:'1',
					text:'添加',
					disabled:true,
					iconCls:'icon-add',
					handler:function(){
						if(tag == null){
							$('#tab').datagrid('appendRow',{
								mc:''
							});
							var lastIndex = $('#tab').datagrid('getRows').length-1;
							$('#tab').datagrid('selectRow', lastIndex);
							$('#tab').datagrid('beginEdit', lastIndex);
							tag = 'add';
						}else{
							$.messager.alert('友情提示','<br/>有存在编辑的行，不允许增加！','error');
						}
					}
				},'-',{
					id:'2',
					text:'修改',
					disabled:true,
					iconCls:'icon-edit',
					handler:function(){
					    var row = $("#tab").datagrid("getSelected");
						if(tag == null && row){
							var rowIndex = $("#tab").datagrid("getRowIndex",row);
							$("#tab").datagrid("beginEdit",rowIndex);
							tag = 'edit';
						}else{
							$.messager.alert('友情提示','<br/>只能选择一条记录修改！','error');
						}
					}
				},'-',{
					id:'3',
					text:'删除',
					disabled:true,
					iconCls:'icon-remove',
					handler:function(){
						var record = $('#tab').datagrid("getSelected");
						if(record){
							$.ajax({
								 url:'/itmanager/yh/jswhcz?tag=delete',
								 type:'post',
								 data:record,
								 success:function(data){
									 if(data == 'success'){
										 $.messager.alert('友情提示','<br/>删除成功！','right');
									 }else{
										 $.messager.alert('友情提示','<br/>删除失败！','error'); 
									 }
									 $('#tab').datagrid('reload');
								 },
								 error:function(data){
									 $.messager.alert('友情提示','<br/>修改失败！','error');
								 }
							 });
						 }else{
						 	$.messager.alert('友情提示','<br/>选择记录！','error');
						 }
						 tag = null;
					}
				},'-',{
					id:'6',
					text:'保存',
					disabled:true,
					iconCls:'icon-save',
					handler:function(){
						$('#tab').datagrid('acceptChanges');
					}
				},'-',{
					id:'7',
					text:'取消',
					disabled:true,
					iconCls:'icon-undo',
					handler:function(){
						$('#tab').datagrid('rejectChanges');
						tag = null;
					}
				}],
				onAfterEdit:function(rowIndex,rowData,changes){//保存时调用
					 $.ajax({
						 url:'/itmanager/yh/jswhcz?tag='+tag,
						 type:'post',
						 data:rowData,
						 success:function(data){
							 if(data == 'success'){
								 $.messager.alert('友情提示','<br/>修改成功！','right');
							 }else{
								 $.messager.alert('友情提示','<br/>修改失败！','error'); 
							 }
							 $('#tab').datagrid('reload');
						 },
						 error:function(data){
							 $.messager.alert('友情提示','<br/>修改失败！','error');
						 }
					 });
					 tag = null;
				},
				onCancelEdit:function(rowIndex,rowData){//取消时调用
				}
			});
			
			 $("#tab").datagrid("getPager").pagination({
				   onSelectPage:function(){
					  $("#tab").datagrid("clearSelections");
					  $("#tab").datagrid("options");
					  $("#tab").datagrid("reload");
				   }
			  });
			 
			 var ens='${param.en}';
			 var en=ens.split(":");
			 for(var i=0;i<en.length;i++){
				 if(en[i] != "" && en[i] != null){
				 	$("#"+en[i]).linkbutton('enable');
				 }
			 }
		});
	</script>
</head>
<body class="easyui-layout">
	<div id="center" region="center" border="false">
		<table id="tab"></table>
	</div>
</body>
</html>